# ----- Always run this at the beginning of class so we can get multi-command output ----- # # Access options from the iPython core from IPython.core.interactiveshell import InteractiveShell # Change the value of ast_node_interactivity InteractiveShell.ast_node_interactivity = "all" # ----- Additional packages we want to import for class ----- # # Import the pandas package import pandas as pd from matplotlib import pyplot as plt import numpy as np # !pip install seaborn # Read in embryo_long_merged.csv embryo_merged = pd.read_csv('data/embryo_long_merged.csv') # Subset the data from our dataset embryo_merged_subset = embryo_merged.iloc[:, :19] # Use the insert method embryo_merged_subset.insert(loc = 4, # Location to insert at column = 'pathogenDose', # The column name after insertion # To calculate the value, we'll pop from the subset value = (embryo_merged_subset.pop('pathogenDose') # Break up the float from the "M" .str.split(pat = "M", expand = True) # Convert the first column to a float, and then provide only that to insert .astype({0:'float64'})[0]) ) # Filter the data by N2 animals with a pathogenDose of 0 N2_mock_data = (embryo_merged_subset.query('wormStrain == "N2" & pathogenDose == 0') # Convert our date variable with the astype() method .astype({'date':'category'}) ) # Take the unique values and flip the order date_list = N2_mock_data.date.unique()[::-1].tolist() # We'll need to pull out and replace the date column N2_mock_data['date'] = (N2_mock_data['date'] # access the categorical property .cat # Reorder the categorical data .reorder_categories(new_categories = date_list) ) # Filter for only uninfected data mean_embryo_data = (embryo_merged_subset.query('doseLevel in ["Mock", "Medium"]') # filter by doseLevel # Group by infection experiment .groupby(by = ['date', 'wormStrain', 'pathogenStrain', 'doseLevel']) # Create the frequency table on numEmbryos .agg({'numEmbryos': 'mean'}) # Recall, when we reset the index, it converts the indices back into columns .reset_index() .astype({'wormStrain':'category', 'doseLevel':'category'}) ) # Pull out our doseLevel data and replace it with a newly categorized version mean_embryo_data['doseLevel'] = (mean_embryo_data['doseLevel'] .cat .reorder_categories(new_categories = ["Mock", "Medium"]) ) # Read the infection signal data in from file infectionSig_data = pd.read_csv("data/infection_signal.tsv", sep = "\t")